# coding: utf-8

from logging_ import create_logger
import os

def create_dir(folders):
	"""创建目录"""
	if not isinstance(folders, list):
		raise TypeError('Argument must be list')
	for fn in folders:
		if not os.path.exists(fn):
			os.makedirs(fn)

def test_func(i):
	file = f'logs/{i}/log.txt'
	create_dir([f'logs/{i}'])
	logger = create_logger(filename=file)
	n = 30
	while n > 0:
		logger.debug(f'[test_{i}] this is a logger debug message: [{n}]')
		# logger.info(f'[test_{i}] this is a logger info message')
		# logger.warning('this is a logger warning message')
		# logger.error('this is a logger error message')
		# logger.critical('this is a logger critical message')
		n -= 1



if __name__ == '__main__':

	from multiprocessing import Pool
	p = Pool(10)
	# 多进程执行脚本
	for i in range(10):
		p.apply_async(test_func, args=(i,))

	p.close()
	p.join()